home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 8010 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: anvil.ugrad.cs.ubc.ca!not-for-mail
  2. From: c2a192@ugrad.cs.ubc.ca (Kazimir Kylheku)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: Pointer arithmetic
  5. Date: 28 Feb 1996 16:37:25 -0800
  6. Organization: Computer Science, University of B.C., Vancouver, B.C., Canada
  7. Message-ID: <4h2sg5INNdg3@anvil.ugrad.cs.ubc.ca>
  8. References: <4h2r55$er@s3.iway.fr>
  9. NNTP-Posting-Host: anvil.ugrad.cs.ubc.ca
  10.  
  11. In article <4h2r55$er@s3.iway.fr>,
  12. Pascal Terracol  <assetsto@pratique.fr> wrote:
  13.  > Hello,
  14.  >
  15.  >this sample code have been correctly working on a pc 80286 processor
  16.  >
  17.  >I put it on a mac and the pointers seems to act differently...
  18.  >any idea about that ? 
  19.  >
  20.  >
  21.  >     int size, n1, n2 ;
  22.  >     Point  *p_debut, *p1, *p2 ;                      /* "vecteur" de translation des adr  */
  23.  >
  24.  >...
  25.  >
  26.  >      n1 = (int) (l->p1)/sizeof(Point) ;
  27.  >         n2 = (int) (l->p2)/sizeof(Point) ;
  28.  >        
  29.  >            p1 = p_debut + n1 ;
  30.  >            p2 = p_debut + n1 ;
  31.  
  32. The declaration for l is missing. It looks like a pointer to a structure, since
  33. you are using it with the -> operator to access members p1 and p2, but what is
  34. that structure with members p1 and p2? It's a little unusual to be _dividing_
  35. by the size of a structure. There are few contexts in which this will yield
  36. correct behavior. It can tell you how many structures will fit into a given
  37. array of characters, provided the array meets alignment restrictions (e.g. it
  38. comes from malloc()). The size of the Point structure will quite certainly
  39. differ between the 80286 and the Mac environment.
  40.  
  41. -- 
  42.  
  43.